导航菜单
首页 >  How to Upload Image File into Database in PHP and MySQL  > How to upload and download files PHP and MySQL

How to upload and download files PHP and MySQL

This tutorial demonstrates how you can upload files of various formats including .zip, .pdf, .docx, .ppt, as well as image files through a form using PHP to be stored in a folder on our server.

We will also record the name of the uploaded files and related info such as the file name, size, and the number of downloads in a database table.

Create a new PHP project folder and call it file-upload-download. Create a subfolder inside this folder called uploads (this is where our uploaded files will be stored),  and a file called index.php. 

index.php is where we will create our file upload form. Open it and put this code inside it:

ez_ad

index.php:

Files Upload and DownloadUpload File upload

It's a very simple form that takes just the input field for our file and an upload button. 

In the head section, we are linking to our style.css file to provide some styling to our form. Create that file in the root of our application and add this CSS code to it:

style.css:

form { width: 30%; margin: 100px auto; padding: 30px; border: 1px solid #555;}input { width: 100%; border: 1px solid #f1e1e1; display: block; padding: 5px 10px;}button { border: none; padding: 10px; border-radius: 5px;}table { width: 60%; border-collapse: collapse; margin: 100px auto;}th,td { height: 50px; vertical-align: center; border: 1px solid black;}vli_ad

 

 

At the top of index.php, we are including filesLogic.php file. This is the file that contains all the logic of receiving our submitted file and saving it to the uploads folder as well as storing the file information in the database. Let's create this file now.

filesLogic.php:

相关推荐: